//! @author Adam Emil Skoog
//! @date   2011-12-17

#include "Image.h"

namespace mehdi
 {
	Image::Image(const std::string &path)
	:
	image(new sf::Image),
	automaticSmoothing(true)
	 {
		if (image->LoadFromFile(path))
			SetImage(*image);
	 }

	Image &Image::setImage(sf::Image *const image)
	 {
		this->image = image;
		return *this;
	 }

	sf::Image *const Image::getImage()
	 {
		return image;
	 }

	Image &Image::setAutomaticSmoothing(const bool &set)
	 {
		automaticSmoothing = set;
		return *this;
	 }

	const bool &Image::hasAutomaticSmoothing() const
	 {
		return automaticSmoothing;
	 }

	void Image::Render(sf::RenderTarget &target) const
	 {
		if (automaticSmoothing)
			image->SetSmooth((automaticSmoothing) ? static_cast<int>(round(GetRotation())) % 90 : false);

		sf::Sprite::Render(target);
	 }
 }
